package org.example.fastproject.core.utils;

import org.example.fastproject.core.bean.SysUserDetails;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Objects;

/**
 * @Author 王海舟
 * @Date 2023/1/20 16:10
 * @PackageName:org.example.fastproject.core.utils
 * @ClassName: SecurityUtil
 * @Description: security工具类
 * @Version 1.0
 */
public class SecurityUtil {
    public static SysUserDetails getUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if(Objects.isNull(authentication))
            return null;
        Object principal = authentication.getPrincipal();
        if(principal instanceof SysUserDetails)
            return (SysUserDetails) principal;
        return null;
    }
}
